package main;

import heartBeat.HeartBeatTask;
import heartBeat.MasterHeartBeatApiInterface;

import java.io.IOException;
import java.net.*;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.sql.SQLException;
import java.util.*;

import dataStore.FtpServerApiInterface;
import dataStore.SlaverDataStoreApiInterface;
import tool.GetMasterApi;
import tool.GetProper;
public class SlaverMain {

	public static void main(String[] args) throws InterruptedException,
			NumberFormatException, NotBoundException, SQLException, IOException {

		/*		FtpApi ftpApi = new FtpApi();
		ftpApi.connect(
	       		"localhost", 
	       		21,
	       		"springwater",
	       		"guohuaquan"
	       		);  

		ftpApi.download_chunk("/home/springwater/program/hybrid-distributed-computing/data/testData/test1.txt",
				"/home/springwater/program/hybrid-distributed-computing/data//testData/test2.txt",
				new Long(10), 
				new Long(10));
        ftpApi.disconnect();
*/
		slaverProper = GetProper.get_properties("conf/config.ini");
		masterHBApi = GetMasterApi.get_masterHBApi(slaverProper);
		masterDSApi = GetMasterApi.get_masterDSApi( slaverProper);
		ftpServerApi = GetMasterApi.get_ftpServerApi( slaverProper);
		start_heart_beat(slaverProper);

//		System.out.println("finished");
	}

	public static	void start_heart_beat( Properties slaverProper) throws RemoteException, UnknownHostException, SQLException
	{
		TimerTask task = new HeartBeatTask(masterHBApi, masterDSApi, ftpServerApi, slaverProper) ;
		long heartBeatInterval = Long.parseLong(slaverProper
				.getProperty("heartBeatInterval"));
		Timer timer = new Timer();
		timer.schedule(task, 0, heartBeatInterval);
	}
	
	static Properties slaverProper;
	static MasterHeartBeatApiInterface masterHBApi; 
	static SlaverDataStoreApiInterface masterDSApi;
	static FtpServerApiInterface ftpServerApi;
}